package com.example.shiropermdemo.modules.app.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class CrosInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //String origin = request.getHeader("Origin");
        //if (StringUtils.isNotBlank(origin)) {
        //    response.setHeader("Access-Control-Allow-Origin", origin);
        //    response.setHeader("Access-Control-Allow-Credentials", "true");
        //    response.setHeader("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
        //    response.setHeader("Access-Control-Allow-Headers", "token,Content-Type,Content-Length,Authorization,Accept,X-Requested-With");
        //    //response.setHeader("Access-Control-Expose-Headers", "*");
        //}
        //
        //
        //String method= request.getMethod();
        //if ("OPTIONS".equals(method)){
        //    response.setStatus(200);
        //    return false;
        //}
        return true;
    }
}
